<? include 'server_config.php'; 

if($_SESSION['user_idx'] =="")
{
	?>
	<script>
		location.href='login.php';
	</script>
	<?
	return;
}


$disease_idx=$_GET['category_idx'];
$page=$_GET['page'];

if($disease_idx=='')
	$disease_idx=0;

if($page=='')
	$page=1;

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
	<title>NextDoorDoctor : 넥스트도어닥터 - 약, 치료</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="Stylesheet" type="text/css" href="./css/nddCommon.css" />
	<script type="text/javascript" src="./js/jquery-1.6.2.min.js"></script>
	<script>
	function cure_display_article(display_user_idx)
	{
		$('#content').load('ndd_cure_document.php', { 'display_user_idx' : display_user_idx});
	}

	function cure_display_list(disease_idx,page)
	{
		$('#img_show_more').attr("src", "./img/loading.gif");

		$('#list').load('ndd_cure_list.php', { 'disease_idx':disease_idx, 'page' : page});
	}	

	function setPosition()
	{
		$("#content").css("height", $(window).height()-157);
		$("#content").css("left", $(window).width()/2+157-62);
		$("#title").css("left", ($(window).width()-968)/2-65);
		$("#line_list_up").css("left", $(window).width()/2+157-62-580);
		$("#line_document_up").css("left", $(window).width()/2+157-62);
	}

	$(window).resize(function() {
		setPosition();
	});
	
	$(document).ready(function(){ 
		cure_display_list('<? echo $disease_idx;?>','<? echo $page;?>' ); 

		setPosition();
		});
							
	</script>
	
	<script type="text/javascript">
		dayName = ["일요일", "월요일", "화요일", "수요일", "목요일", "금요일", "토요일"];
		second = 1000;
		minute = second * 60;
		hour = minute * 60;
		day = hour * 24;

		getTimestring = function(time) {

		var now = new Date();
		var diff = now - time;

		var dhour = Math.floor(diff / hour);
		diff -= dhour * hour;
		var dminute = Math.floor(diff / minute);
		diff -= dminute * minute;
		var dsecond = Math.floor(diff / second);
		diff -= dsecond * second;

		var timeStringKorean = "";
		  timeStringKorean = time.getFullYear() + "년 ";
		  timeStringKorean += (time.getMonth() + 1) + "월 ";
		  timeStringKorean += time.getDate() + "일 " + dayName[time.getDay()] + " ";
		  var timeTimeStringKorean = "";
		  if (time.getHours() < 12)
		  {
			timeTimeStringKorean += "오전 ";
			if (time.getHours() == 0)
			  timeTimeStringKorean += "12:";
			else if (time.getHours() < 10)
			  timeTimeStringKorean += "0" + time.getHours() + ":";
			else
			  timeTimeStringKorean += time.getHours() + ":"
		  }
		  else
		  {
			timeTimeStringKorean += "오후 ";
			if (time.getHours() == 12)
			  timeTimeStringKorean += "12:";
			else if (time.getHours() < 22)
			  timeTimeStringKorean += "0" + (time.getHours() - 12) + ":";
			else
			  timeTimeStringKorean += (time.getHours() - 12) + ":";
		  }
		  if (time.getMinutes() >= 10)
			timeTimeStringKorean += time.getMinutes();
		  else
			timeTimeStringKorean += "0" + time.getMinutes();
		  timeTimeStringKorean += ":"
		  if (time.getSeconds() >= 10)
			timeTimeStringKorean += time.getSeconds();
		  else
			timeTimeStringKorean += "0" + time.getSeconds();
		timeStringKorean += timeTimeStringKorean;

		var timestring;
		if (time.toDateString() != now.toDateString())
		{
		  now.setHours(0);
		  now.setMinutes(0);
		  now.setSeconds(0);
		  diff = now - time;
		  var dday = Math.ceil(diff / day);
		  if (dday == 1)
			timestring = "어제 " + timeTimeStringKorean.replace(/:..$/, '');
		  else if (now.getDay() - dday >= 1 && dday <= 3)
		  {
			timestring = dayName[time.getDay()] + " " + timeTimeStringKorean.replace(/:..$/, '');
		  }
		  else
		  {
			if (time.getYear() < now.getYear())
			  timestring = timeStringKorean.replace(/일 .+일/, '일').replace(/:..$/, ''); 
			else
			  timestring = timeStringKorean.replace(/.+년 /, '').replace(/일 .+일/, '일').replace(/:..$/, '');
		  }
		}
		else if (dhour > 1)
		  timestring = dhour + "시간 전";
		else if (dhour == 1)
		  timestring = "약 1시간 전";
		else if (dminute > 1)
		  timestring = dminute + "분 전";
		else if (dminute == 1)
		  timestring = "약 1분 전";
		else if (dsecond > 0)
		  timestring = dsecond + "초 전";

		return timestring;

		};
		function getDateStr(y,m,d,h,min,s) {
		  var res = new Date(y, m-1, d, h, min, s);
//		  alert(m);
		  //alert(h + ' ' + min + ' ' + s);
//		  var d = new Date(date_string);

//		alert(res);
			return getTimestring(res);
		}
		var d = new Date(2011, 07, 22, 00, 11);

	</script>
 </head>

 <body>
 <div id="menu_expand"><span></span></div>
	<div id='wrapper'>
        <?
        include "top_menu.php";
        ?>
		
		<div id='left_bg'>
		</div>

		<div id="title" style="position:fixed;padding-left:72px;top:50px;background:#fff;">
			<div id='title_margin_top'><span></span></div>
			<div style='width:41px;height:29px;float:left;'><img src="./img/top_icon_talk.png"></div>
			<div style='height:29px;float:left;margin-top:3px;'><span id='article_content' >총 <? echo number_format($article_count);?>개의 약, 치료가 있습니다.&nbsp;</span></div>
			<div style='height:29px;float:left;'>
			
			&nbsp;&nbsp;
			<a href='ndd_cure_drug.php'>
				<img src="./img/cure_add.png" border="0">
			</a>
			
			</div>
		</div>
		
		<div id='list' style="padding-top:108px;">

		</div>

		<div id='middle_bg'>
		</div>

		<div id='content'>
		</div>

		
		<iframe src='' name='ifr_temp' style='display:none;'></iframe>

		<div style='position:fixed;top:156px;height:2px;width:565px;background:#cccccc;' id="line_list_up"><span><span></div>
		<div style='position:fixed;top:156px;height:2px;width:388px;background:#cccccc;' id="line_document_up"><span><span></div>


	</div>
 </body>
</html>

 
<?

function utf8_strcut( $str, $size )
{
        $substr = substr( $str, 0, $size * 2 );
        $multi_size = preg_match_all( '/[\\x80-\\xff]/', $substr, $multi_chars );

        if ( $multi_size > 0 )
            $size = $size + intval( $multi_size / 3 ) - 1;

        if ( strlen( $str ) > $size )
        {
            $str = substr( $str, 0, $size );
            $str = preg_replace( '/(([\\x80-\\xff]{3})*?)([\\x80-\\xff]{0,2})$/', '$1', $str );
            $str .= '...';
        }

        return $str;
}
?>